package com.study.goodsserivceprovider.feign;


import com.study.api.Result;
import com.study.clients.IGoodsFeignClient;
import com.study.dto.ItemStockDto;
import com.study.goodsserivceprovider.converter.ItemConverter;
import com.study.goodsserivceprovider.domain.ItemStockDo;
import com.study.goodsserivceprovider.mapper.entitys.TbItem;
import com.study.goodsserivceprovider.service.IItemService;
import com.study.vo.ItemDetailVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
public class GoodsFeignClient implements IGoodsFeignClient {

    @Autowired
    IItemService itemService;

    @Autowired
    ItemConverter itemConverter;

    @Override
    public Result<List<ItemDetailVo>> getItemsByIds(List<Long> ids) {
        log.info("begin GoodsFeignClient.getItemsByIds:"+ids);
        List<TbItem> itemList=itemService.findItemsByIds(ids);
        List<ItemDetailVo> itemDetailVos=itemConverter.itemDetail2VoList(itemList);
        return new Result.Builder<List<ItemDetailVo>>().data(itemDetailVos).ok().bulider();
    }

    @Override
    public Result decreaseStock(List<ItemStockDto> itemStockDtos) {
        log.info("begin GoodsFeignClient.decreaseStock:"+itemStockDtos);
        List<ItemStockDo> itemStockDos=itemConverter.itemStockDo2DoList(itemStockDtos);
        boolean rs=itemService.decreaseStock(itemStockDos);
        return new Result.Builder<>().ok().bulider();
    }
}
